<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>仿京东密码登陆</title>
    <style>
        .box{
            width:400px;
            border-bottom:1px solid #ccc;
            margin: 100px auto;
            position: relative;
        }
        .box input{
            width:370px;
            height:30px;
            border:0;
        }
        .box button{
            position: absolute;
            top:3px;
            right:-20px;
        }
    </style>
</head>
<body>
    <div class="box">
        <label for="password">
            <button id="eye">按钮</button>
        </label>
        <input type="password" name="password" id="password">
    </div>
    <script>
        var eye = document.getElementById('eye');
        var pwd = document.getElementById('password');
        var flag = 0;
        eye.onclick = function () {
            
            if(flag==0){
                // alert('1');
                pwd.type = 'text';
                flag=1;
            } else {
                pwd.type = 'password';
                flag=0;
            }
        }
    </script>
</body>
</html>